<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui-flex.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui-list-swipe.css" />
    <style>
        body {}
    </style>
</head>

<body>
    <header id='header' class="aui-bar aui-bar-nav" style="background-color: #03a9f4">
        <a class="aui-pull-left aui-btn" onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="middle">
            指示配送备货
        </div>
    </header>
    <div class="aui-content">
        <div style="background-color:white; height: 10rem;width: 100%;">
            <p id="planQty" style="font-size:0.9rem;color: #1abc9c;"></p>
            <div style="height:9rem;overflow-y:auto;">
                <table class="table" style='width:100%;' id="table">
                    <thead>
                        <tr
                            style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 12px;font-weight: bold;">
                            <!-- <td algin='center' style="width:50px;">序号</td> -->
                            <td algin='center' style="width:120px;;">物料号</td>
                            <td algin='center' style="width:120px;">配送数量</td>
                            <td algin='center' style="width:100px;">批次号</td>
                            <!-- <td algin='center' style="width:100px;">包装数</td> -->
                            <td algin='center' style="width:90px;">源库</td>
                            <td algin='center' style="width:100px;">源库位</td>
                        </tr>
                    </thead>
                    <tbody id="tbodyHtml">
                    </tbody>
                </table>
            </div>
        </div>

        <div style="background-color:white; height: 100%;width: 100%;padding-top: 1px;">
            <p id="countQty" style="font-size:0.9rem;color: #e51c23;padding-top: 4px;height: 1.5rem;"></p>

            <ul class="ui-selectee" id="tbodyHtmlS">

            </ul>
        </div>

    </div>


</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../script/aui-list-swipe.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var scanRule = ""; //条码解析规则
    apiready = function () {
        var paTaskCode = api.pageParam.paTaskCode;
        var mrlCode = api.pageParam.mrlCode;
        var mrlName = api.pageParam.mrlName;

        var title = "查看-" + mrlName;
        console.log(title);
        document.getElementById("middle").innerHTML = title;

        getPaTaskDetailInfo(paTaskCode, mrlCode);
        // getPaDistributeMrlRels(paTaskCode, mrlCode);
    };

    var swipe = new ListSwipe();
    var planQty = 0;
    var countQty = 0;

    function closeWin() {
        api.closeWin();
        // api.execScript({
        //     name: 'paAndonDistribute',
        //     script: 'getDistributeMrlInfo("' + api.pageParam.paTaskCode + '");'
        // });
    }
    // 获取-对应的 配送任务明细信息
    function getPaTaskDetailInfo(paTaskCode, mrlCode) {
        console.log("paTaskCode", paTaskCode);
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/searchPaTaskDetailInfo";

        var params = new Object();
        params.url = url;
        params.method = 'post';
        params.dataType = 'json';
        var un = localStorage.getItem('un');
        var data = {
            values: {
                paTaskCode: paTaskCode,
                
                mrlCode: mrlCode,
                un: un
            }
        };
        api.showProgress({
            title: '查询中...',
        });
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                api.hideProgress();
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    var list = myobj.list;
                    planQty = myobj.planqty;
                    var html = "";
                    //遍历
                    for (var i = 0; i < list.length; i++) {

                        html += "<tr style='text-align: center;color: black;font-size: 12px;background-color: #F5F5F5;'>";
                        html += "<td name='mrlCode'>" + list[i].sub_mrlcode + "</td>";
                        html += "<td name='planqty'>" + list[i].planQty + "</td>";
                        html += "<td name='uda2n'>" + list[i].ext17 + "</td>";
                        // html += "<td name='uda3c'>" + list[i].ext18 + "</td>";
                        html += "<td name='uda4c'>" + (list[i].ext19 == null ? "" : list[i].ext19) + "</td>";
                        html += "<td name='uda4n'>" + (list[i].ext20 == null ? "" : list[i].ext20) + "</td>";
                        html += "</tr>";
                    }
                    $api.html($api.byId("tbodyHtml"), html);
                    $api.html($api.byId("planQty"), "计划数量：" + planQty);
                    getPaDistributeMrlRels(paTaskCode, mrlCode);
                } else if (myobj.code == "1") {
                    //失败
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });

    }
    function getPaDistributeMrlRels(paTaskCode, mrlCode) {
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/searchPaDistributeMrlRels";

        var params = new Object();
        params.url = url;
        params.method = 'post';
        params.dataType = 'json';
        var un = localStorage.getItem('un');
        var data = {
            values: {
                paTaskCode: paTaskCode,
                mrlCode: mrlCode,
                un: un
            }
        };

        api.showProgress({
            title: '查询中...',
        });
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                api.hideProgress();
                console.log("retretretret" + ret);
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    var list = myobj.list;
                    countQty = myobj.countQty;
                    var html = "";
                    console.log("listlist" + list);
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        html += "<div class='aaui-btn-info aui-btn-block' style='margin-bottom: 10px;color: black !important;background-color: #addbef !important;height: 110px;padding: 0.2rem 0.2rem;font-size: 0.7rem;'>";
                        html += "<table style='width:100%;'>";
                        html += "<tr style='width:100%;'><td style='width:16%;'>箱号：</td><td  id='boxnumInfo' style='width:70%;' colspan='2'>" + list[i].box_code + "</td><td></td></tr>";
                        html += "<tr style='width:100%;'><td style='width:20%;'>物料号：</td> <td  id='mrlCodeInfo' style='width:70%;' colspan='3'>" + list[i].mrl_code + "</td></tr>";
                        html += "<tr style='width:100%;'><td style='width:20%;'>物料名：</td> <td  id='mrlNameInfo' style='width:70%;' colspan='3'>" + list[i].mrl_name + "</td></tr>";
                        html += "<tr style='width:100%;'><td style='width:20%;'>批次号：</td><td id='lotCodeInfo' style='width:40%;' >" + list[i].lot_code + "</td> ";
                        html += "<td style='width:16%;'>数量：</td><td id='qtyInfo' style='width:20%;'>" + list[i].ext15 + "</td>";
                        html += "</tr>";
                        html += "</table></div>";

                    }
                    $api.html($api.byId("tbodyHtmlS"), html);
                    $api.html($api.byId("countQty"), "备货数量：" + countQty);
                    console.log("countQty" + Number(countQty));
                    console.log("planQty11" + planQty);
                    console.log(Number(countQty) >= Number(planQty));
                    if (Number(countQty) >= Number(planQty)) {
                        //若备货数量>=计划数量，则改变字体颜色为绿色
                        $api.html($api.byId("countQty"), "备货数量：" + countQty + " （已满足）");
                        document.getElementById("countQty").style.color = "#1abc9c";
                    } else {
                        $api.html($api.byId("countQty"), "备货数量：" + countQty + " （未满足）");
                    }

                } else if (myobj.code == "1") {
                    //失败
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    

</script>

</html>